#include <iostream>
#include <unistd.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <cerrno>
#include <cassert>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
using namespace std;
char const *pathname = ".";
const int project_id = 1;
#define SIZE 4096

key_t Getkey()
{
    key_t ret = ftok(pathname, project_id);
    if (ret == -1)
    {
        cout << "error:" << errno << strerror(errno) << endl;
        exit(1);
    }
    return ret;
}

int Createshm(key_t k, int size)
{
    umask(0);
    int ret = shmget(k, size,IPC_CREAT | IPC_EXCL|0666);
    if (ret == -1)
    {
        cout << "error:" << errno << strerror(errno) << endl;
        exit(2);
    }
    return ret;
}

int Getshm(key_t k, int size)
{
    int ret = shmget(k, size, IPC_CREAT);
    if (ret == -1)
    {
        cout << "error:" << errno << strerror(errno) << endl;
        exit(3);
    }
    return ret;
}


char* attachshm(int shmid)
{
return (char*)shmat(shmid,nullptr,0);

}


void deatchshm(char* shmaddr)
{
    shmdt(shmaddr);
}


void Delshm(int shmid)
{
    shmctl(shmid, IPC_RMID, nullptr);
}





